
import Mock from "mockjs";
import { Local } from "../utils";
class dicDetailEntity {
  fieldsSession = Local('dicDetail-fields', Mock.mock([{
    sys_user_sex:[
      {
        id:"1",
        name:"aaa",
        key:"0",
        type:"sys_user_sex",
        sort:"1",
        status:"1",
        remarks:"性别男",
        createTime:"2023-05-30 22:52:37",
      },
      {
        id:"2",
        name:"aaa",
        key:"0",
        type:"sys_user_sex",
        sort:"1",
        status:"1",
        remarks:"性别男",
        createTime:"2023-05-30 22:52:37",
      },
      {
        id:"3",
        name:"aaa",
        key:"0",
        type:"sys_user_sex",
        sort:"1",
        status:"1",
        remarks:"性别男",
        createTime:"2023-05-30 22:52:37",
      }
    ]
  },
  {
    sys_user_ses:[
      {
        id:"1",
        name:"aaa",
        key:"0",
        type:"sys_user_ses",
        sort:"1",
        status:"1",
        remarks:"性别男",
        createTime:"2023-05-30 22:52:37",
      },
      {
        id:"2",
        name:"aaa",
        key:"0",
        type:"sys_user_ses",
        sort:"1",
        status:"1",
        remarks:"性别男",
        createTime:"2023-05-30 22:52:37",
      },
    ]
  }
  ]))
  get fields() {
    return this.fieldsSession.get();
  }
  set fields(obj: any) {
    this.fieldsSession.set(obj)
  }
  findAll() {
    return this.fields;
  }

  detailAdd(res:any){
    const obj = this.findAll();
     obj.push(res)
     this.fields = obj;
  }
  detailedit(res:any){
    let arr = this.findAll();
   arr.forEach((x:any,index:any) => {
         if(x.id === res.id)
         {
           arr.splice(index,1,res);
          
         }
     })
     this.fields = arr;
   }
  search(res:any){
    let arr = this.findAll();
    let keys = Object.keys(arr[0]);
    keys.forEach((x:any,index:any) => {
          if(x == res)
          {
              this.fields = arr[index][x];
          }
      })
  }

}

export default dicDetailEntity;